package com.hxd.otc.module.wallet.adapter;

import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hxd.otc.R;
import com.hxd.otc.common.UserHelper;
import com.hxd.otc.module.wallet.bean.WalletCoinRecordBean;
import com.hxd.otc.utils.DateUtil;
import com.hxd.otc.utils.StringUtil;
import com.hxd.otc.utils.UIUtils;

import java.math.BigDecimal;
import java.util.List;

/**
 * 描  述 :  ${钱包记录 Adapter}
 */
public class CoinRecordAdapter extends BaseQuickAdapter<WalletCoinRecordBean.WalletCoinRecordData, BaseViewHolder> {

    public CoinRecordAdapter(@Nullable List<WalletCoinRecordBean.WalletCoinRecordData> data) {
        super(R.layout.list_item_wallet_coin_record, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, WalletCoinRecordBean.WalletCoinRecordData item) {

        helper.setText(R.id.tv_time, DateUtil.format(Long.parseLong(item.createTime),DateUtil.YY_MM_DD_HH_MM_SS));
        BigDecimal amountCoinDecimal = new BigDecimal(item.amountCoin);
        if (item.orderType.equals("1")) {//充值：商户到账的数量=通兑数量-通兑手续费，用户扣除数量=通兑数量
            helper.setText(R.id.tv_content, UIUtils.getContext().getString(R.string.recharge));
            if (UserHelper.getId().equals(item.fromUserId)) { //用户扣除数量=通兑数量
                helper.setText(R.id.tv_number, "-" + StringUtil.format8Number(amountCoinDecimal.doubleValue()) + item.coinType);
            } else { //商户到账的数量=通兑数量-通兑手续费
                BigDecimal toFeeDecimal = new BigDecimal(item.toFee);
                BigDecimal resultDecimal = amountCoinDecimal.subtract(toFeeDecimal);
                helper.setText(R.id.tv_number, "+" + StringUtil.format8Number(resultDecimal.doubleValue()) + item.coinType);
            }
        } else {//提现：商户扣除数量=通兑数量+手续费，用户到账数量=通兑数量
            helper.setText(R.id.tv_content, UIUtils.getContext().getString(R.string.withdraw_money));
            if (UserHelper.getId().equals(item.fromUserId)) { //商户扣除数量=通兑数量+手续费
                BigDecimal fromFee = new BigDecimal(item.fromFee);
                BigDecimal resultDecimal = amountCoinDecimal.add(fromFee);
                helper.setText(R.id.tv_number, "-" + StringUtil.format8Number(resultDecimal.doubleValue()) + item.coinType);
            } else { //用户到账数量=通兑数量
                helper.setText(R.id.tv_number, "+" + StringUtil.format8Number(amountCoinDecimal.doubleValue()) + item.coinType);
            }
        }


//        if (item.status == 1) {
//            helper.setGone(R.id.tv_statues, true);
//            helper.setText(R.id.tv_statues, UIUtils.getContext().getString(R.string.under_review));
//        } else if (item.status == 2) {
//            helper.setGone(R.id.tv_statues, true);
//            helper.setText(R.id.tv_statues, UIUtils.getContext().getString(R.string.failed_to_withdraw_coins));
//        } else {
//            helper.setGone(R.id.tv_statues, false);
//        }
    }
}
